package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzShoucang;
import com.ruoyi.system.service.IDzShoucangService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 收藏Controller
 * 
 * @author ruoyi
 * @date 2023-09-22
 */
@RestController
@RequestMapping("/api/shoucang")
public class DzShoucangApiController extends BaseController
{
    @Autowired
    private IDzShoucangService dzShoucangService;

    /**
     * 查询收藏列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzShoucang dzShoucang)
    {
        startPage();
        List<DzShoucang> list = dzShoucangService.selectDzShoucangListWeb(dzShoucang);
        return getDataTable(list);
    }

    /**
     * 导出收藏列表
     */
    @Log(title = "收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzShoucang dzShoucang)
    {
        List<DzShoucang> list = dzShoucangService.selectDzShoucangListWeb(dzShoucang);
        ExcelUtil<DzShoucang> util = new ExcelUtil<DzShoucang>(DzShoucang.class);
        util.exportExcel(response, list, "收藏数据");
    }

    /**
     * 获取收藏详细信息
     */
    @GetMapping(value = "/{scId}")
    public AjaxResult getInfo(@PathVariable("scId") Long scId)
    {
        return AjaxResult.success(dzShoucangService.selectDzShoucangByScId(scId));
    }

    /**
     * 新增收藏
     */
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzShoucang dzShoucang)
    {
        return toAjax(dzShoucangService.insertDzShoucang(dzShoucang));
    }

    /**
     * 修改收藏
     */
    @Log(title = "收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzShoucang dzShoucang)
    {
        return toAjax(dzShoucangService.updateDzShoucang(dzShoucang));
    }

    /**
     * 删除收藏
     */
    @Log(title = "收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scIds}")
    public AjaxResult remove(@PathVariable Long[] scIds)
    {
        return toAjax(dzShoucangService.deleteDzShoucangByScIds(scIds));
    }
}
